<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="com.bookingService.*"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

<script type="text/javascript"
	src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDM_Em3f2cY7sOe7_qdqo8leShzCnPRF2Y&sensor=false"></script>
<script type="text/javascript" src="js/mapscript.js"></script>

<title>Flights</title>


</head>

<body onload="initialize()">
<center>
	<div style="display: inline-block;">
		<form action="index.jsp" method="post">
			<table border="1" id="flights" style="display: inline-block;">
				<tr style="background-color: gray;">
					<td>Airline</td>
					<td>From</td>
					<td>To</td>
					<td>Available seats</td>
					<td>Fare</td>
					<td colspan="2">Reserv</td>
				</tr>

				<%
					List<Booking> bl = BookingService.getBookingList();

					String choise = request.getParameter("choise");

					if (choise != null) {
						Booking booking = bl.get(Integer.parseInt(choise));
						booking.setAvailableSeats(booking.getAvailableSeats() - 1);
						BookingService.saveBookingList(bl);
						response.sendRedirect("index.jsp");
					}

					for (int i = 0; i < bl.size(); i++) {
						Booking booking = bl.get(i);

						if (i % 2 == 0){
				%>
				<tr style="background-color: #EEE8CD;">
					<%
						}else{
					%>
				
				<tr><%} %>

					<td><%=booking.getAirline()%></td>
					<td><%=booking.getOriginCity()%></td>
					<td><%=booking.getDestinationCity()%></td>
					<td><%=booking.getAvailableSeats()%></td>
					<td>
						<%
							for (FareEntry entry : booking.getFare().entry) {
						%> <%=entry.currency + " " + entry.value%><br> <%
 	}
 %>
					</td>
					<td><input type="radio" name="choise" class="choise"
						value="<%=i%>"></td>

					<td><a onclick="showAirport('<%=booking.getAirportAddress()%>') " href="#">Show</a>
						<div style="display: none"><%=bl.get(i).getAirportAddress()%></div>
					</td>

				</tr>



				<%
					}
				%>
				<tr>
					<td colspan="7"><input type="submit" value="Reserv"></td>
				</tr>
			</table>
		</form>
	</div>


	<div id="map_canvas"
		style="width: 500px; height: 300px; display: inline-block;"></div>


<h3>Converter</h3>
		<table>


			<%
				CurrencyConversionWS ccw = new CurrencyConversionWS();
			%>
			<tr>
				<td><div id="resultText"></div></td>
			</tr>


			<tr>
				<select id="from">
					<%
						for (String code : ccw.GetCurrencyCodes()) {
					%>
					<option value="<%=code.substring(0, 3)%>"><%=code%>
					</option>
					<%
						}
					%>

				</select> ->

				<select id="to">
					<%
						for (String code : ccw.GetCurrencyCodes()) {
					%>
					<option value="<%=code.substring(0, 3)%>"><%=code%>
					</option>
					<%
						}
					%>

				</select>
			</tr>
			<tr>
				<td>Write amount :<input type="text" id="amount"
					onkeypress='validate(event)'></td>
			</tr>
			<tr>
				<td><input type="button" onClick="conversionCurrency()" value="Convert"></td>
			</tr>
		</table>
</center>

</body>
</html>